﻿using System;
using System.Net;
using System.Runtime.Serialization;

namespace Airport
{
    [DataContract]
    public class Flight : IFlight, IEquatable<Flight>
    {
        private int _flightId;
        private string _airlineCode;
        private int _flightNumber;
        private string _flightName;
        private int _squawk;
        private bool _isActive;
        //private Plane _flightPlane;

        public Flight()
            : this(-1, "", -1, "", -1, false/*, new Plane()*/)
        {
        }

        public Flight(int flightId, string airlineCode, int flightNumber, string flightName, int squawk, bool isActive/*, Plane flightPlane*/)
        {
            _flightId = flightId;
            _airlineCode = airlineCode;
            _flightNumber = flightNumber;
            _flightName = flightName;
            _squawk = squawk;
            _isActive = isActive;
            //_flightPlane = flightPlane;
        }

        [DataMember]
        public int FlightId
        {
            get { return _flightId; }
           
            set
            {
                if (_flightId != value)
                {
                    _flightId = value;
                }
            }
        }

        [DataMember]
        public string AirlineCode
        {
            get { return _airlineCode; }
           
            set
            {
                if (_airlineCode != value)
                {
                    _airlineCode = value;
                }
            }
        }

        [DataMember]
        public int FlightNumber
        {
            get { return _flightNumber; }
            
            set
            {
                if (_flightNumber != value)
                {
                    _flightNumber = value;
                }
            }
        }

        [DataMember]
        public string FlightName
        {
            get { return _flightName; }

            set
            {
                if (_flightName != value)
                {
                    _flightName = value;
                }
            }
        }

        [DataMember]
        public int Squawk
        {
            get { return _squawk; }
           
            set
            {
                if (_squawk != value)
                {
                    _squawk = value;
                }
            }
        }

        [DataMember]
        public bool IsActive
        {
            get { return _isActive; }
            
            set
            {
                if (_isActive != value)
                {
                    _isActive = value;
                }
            }
        }

        /*
        [DataMember]
        public Plane FlightPlane
        {
            get { return _flightPlane; }
          
            set
            {
                if (_flightPlane != value)
                {
                    _flightPlane = value;
                }
            }
        }
        */

        public bool Equals(Flight other)
        {
            if (other == null)
            {
                return false;
            }

            if (_flightId != other._flightId)
            {
                return false;
            }

            return true;
        }
    }
}
